package environment;

import javax.swing.JTextArea;

public abstract class IO {
	private static int printLevel = 999;
	private static JTextArea operatorText;
	private static JTextArea clientText;
	
	public static final int DEBUG = 4;
	public static final int INFO = 3;
	public static final int IMPORTANT = 2;
	public static final int TOP = 1;
	
	
	/**
	 * Core printing method.
	 * @param x String to be printed to console
	 */
	private static void printConsole(String x)
	{
		System.out.println(x);		
	}
	
	public static void init(int printLev, JTextArea operators, JTextArea clients)
	{
		printLevel = printLev;
		operatorText = operators;
		clientText = clients;
	}

	public static void clientPrint(String x, int importance)
	{
		if (importance > printLevel)
			return;
			
		if (clientText == null)
			printConsole(x);
		else
		{
			if (clientText.getText().length() > 512*512)
				clientText.setText("");
			
			clientText.append(x + "\n");
			clientText.setCaretPosition(clientText.getDocument().getLength());
		}
	}
	
	public static void operatorPrint(String x, int importance)
	{

		if (importance > printLevel)
			return;
			
		if (operatorText == null)
			printConsole(x);
		else
		{
			operatorText.append(x+ "\n");
			operatorText.setCaretPosition(operatorText.getDocument().getLength());
		}
	}
	
	public static void envPrint(String x, int importance)
	{
		if (importance > printLevel)
			return;
			
		printConsole(x);
	}
}
